/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_DXVERTEXDECLARATION_H
#define M_DXVERTEXDECLARATION_H

#include "vertexdeclaration.h"
#include "comptr.h"
#include "dxrendersystem.h"

#include "dxheaders.h"

namespace Engine
{
	/**
	*  This class declares the format of a set of vertex inputs, which can be issued to the rendering API.
	*/
	class DXVertexDeclaration: public VertexDeclaration
	{
	public:

		friend class DXRenderSystem;

		virtual ~DXVertexDeclaration();

		/**
		*   Adds a new VertexElement to this declaration.
		*/
		virtual const VertexElement& AddElement(unsigned short source, size_t offset, VertexElementType theType, VertexElementSemantic semantic, unsigned short index);

		/**
		*   Remove the element at the given index from this declaration.
		*/
		virtual void RemoveElement(unsigned short elem_index);

		/**
		*   Remove the element at the given index from this declaration.
		*/
		virtual void RemoveElement(const VertexElement* elem);

		/**
		*   Remove all elements.
		*/
		virtual void RemoveAllElements(void);

		/**
		*   Return directx specific vertex declaration.
		*/
		IDirect3DVertexDeclaration9* GetVertexDeclaration();

		/**
		*   Update offsets for all elements.
		*/
		virtual void UpdateOffsets();
	private:

		/**
		*  Standard constructor
		*/
		DXVertexDeclaration(DXRenderSystem* renderSystem);

	private:

		DXRenderSystem* m_renderSystem;

		bool m_needUpdate;

		ComPtr<IDirect3DVertexDeclaration9> m_vertexDeclaration;
	};
}

#endif
